package com.lmf.annotation.controller;

import com.lmf.annotation.service.MyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import javax.inject.Inject;

@Controller
public class MyController {

    //自动装配都是从容器中获取的参数，进行注入的

    @Qualifier(value = "myService")
    @Autowired(required = false)  //required = false 表示若没有找到可用的bean，也不用报错；
    private MyService myService;
    @Resource(name = "myService_2")  //不支持@Primary功能，默认注入就是属性名的bean
    private MyService myService2;
    @Inject()   //不支持 required 参数
    private MyService myService3;

    @Override
    public String toString() {
        return "MyController{" +
                "myService=" + myService +
                ", myService2=" + myService2 +
                ", myService3=" + myService3 +
                '}';
    }
}
